package com.gs.api.projects.bzapplets.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gs.api.projects.bzapplets.dao.BzFavoriteDao;
import com.gs.api.projects.bzapplets.entity.BzFavorite;
import com.gs.api.projects.bzapplets.vo.BzWallpaperVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author guoyunfei on 2021/7/11 3:40
 * @className BzCollectionService
 * @description TODO
 * @Version 1.0
 */

@Service
@Transactional
public class BzFavoriteService extends ServiceImpl<BzFavoriteDao,BzFavorite> {

    @Autowired
    private BzFavoriteDao bzFavoriteDao;


    @Transactional
    public int deleteByWallpaperId(Integer wallpaperId,String openid,Integer type,String appid){
        Map<String,Object> map = new HashMap<>();
        map.put("wallpaperId",wallpaperId);
        map.put("openid",openid);
        map.put("type",type);
        map.put("appid",appid);
        return bzFavoriteDao.deleteByWallpaperId(map);
    }

    public int selectCount(BzFavorite collection){
        return bzFavoriteDao.selectCount(collection);
    }

    /**
     * 获取我的收藏，浏览，点赞数据
     * @param wallpaperVo
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<BzWallpaperVo> getMyData(BzWallpaperVo wallpaperVo,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        final PageInfo<BzWallpaperVo> userPageInfo = new PageInfo<>(bzFavoriteDao.getMyData(wallpaperVo));
        return userPageInfo;
    }

    public PageInfo<BzWallpaperVo> getMyDataNew(BzWallpaperVo wallpaperVo,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        final PageInfo<BzWallpaperVo> userPageInfo = new PageInfo<>(bzFavoriteDao.getMyDataNew(wallpaperVo));
        return userPageInfo;
    }


}
